import * as ActionTypes from '../constant/ActionTypes';

// 1. 设计 state
/*
const initialState = {
    counter: 0
};
*/



/*
 * action 创建函数
 * 函数名称设计成与组件属性名称相同
 */

export function increaseCounter() {
    return {
        type: ActionTypes.INCREASE_COUNTER
    };
}

export function decreaseCounter() {
    return {
        type: ActionTypes.DECREASE_COUNTER
    };
}

export function increaseCounterIfOdd() {
    return ((dispatch, getState) => {
        if (getState().counter % 2 === 0) {
            return;
        }
        dispatch(increaseCounter());
    });
}

export function increaseCounterDelay(delay = 1000) {
    return ((dispatch, getState) => {
        setTimeout(() => {
            dispatch(increaseCounter());
        }, delay);
    });
}
